package com.hrp.controller;

import com.hrp.domain.ResponseData;
import com.hrp.domain.TransportRecord;
import com.hrp.domain.User;
import com.hrp.service.TransportRecordService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created by Administrator on 2019-04-27.
 */
@RestController
@RequestMapping("transprotRecord")
public class TransportRecordController {

    @Autowired
    private TransportRecordService transportRecordService;



    @RequestMapping("/getTransportRecordByPage")
    public Map<String,Object> getTransportRecordByPage(Integer page, Integer rows) {
//        Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
//        List<Jxkhzq> list =  jxkhzqService.getAllKhzq();
//        jsonMap.put("total", list.size());//total键 存放总记录数，必须的
//        jsonMap.put("rows", list);//rows键 存放每页记录 list
        User acount = (User)SecurityUtils.getSubject().getPrincipal();
        return transportRecordService.getTransportRecordByPage(page,rows,acount.getUsername());
    }

    @RequestMapping("/saveTransportRecordData")
    public ResponseData saveTransportRecordData(TransportRecord transportRecord) {
//        Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
//        List<Jxkhzq> list =  jxkhzqService.getAllKhzq();
//        jsonMap.put("total", list.size());//total键 存放总记录数，必须的
//        jsonMap.put("rows", list);//rows键 存放每页记录 list
        User acount = (User) SecurityUtils.getSubject().getPrincipal();
        transportRecord.setCzry(acount.getUsername());
        return transportRecordService.saveTransportRecordData(transportRecord);
    }

    @RequestMapping("/updateTransportRecordDataPrice")
    public ResponseData updateTransportRecordDataPrice( @RequestParam(name = "price", defaultValue = "0") Integer price,
                                                       @RequestParam(name = "sendTimeKsrq", defaultValue = "2018-01-01") String sendTimeKsrq,
                                                       @RequestParam(name = "sendTimeJsrq", defaultValue = "2018-01-01") String sendTimeJsrq,
                                                       @RequestParam(name = "varietiesIdStr", defaultValue = "-1") String varietiesIdStr,
                                                       @RequestParam(name = "supplierIdStr", defaultValue = "-1") String supplierIdStr,
                                                       @RequestParam(name = "receiverIdStr", defaultValue = "-1") String receiverIdStr) {
        return transportRecordService.updateTransportRecordDataPrice(price,sendTimeKsrq,sendTimeJsrq,varietiesIdStr,supplierIdStr,receiverIdStr);
    }


    @RequestMapping("/updateIsSettleAccounts")
    public ResponseData updateIsSettleAccounts( @RequestParam(name = "isSettleAccounts", defaultValue = "0") Integer isSettleAccounts,
                                                        @RequestParam(name = "sendTimeKsrq", defaultValue = "2018-01-01") String sendTimeKsrq,
                                                        @RequestParam(name = "sendTimeJsrq", defaultValue = "2018-01-01") String sendTimeJsrq,
                                                        @RequestParam(name = "varietiesIdStr", defaultValue = "-1") String varietiesIdStr,
                                                        @RequestParam(name = "supplierIdStr", defaultValue = "-1") String supplierIdStr,
                                                        @RequestParam(name = "receiverIdStr", defaultValue = "-1") String receiverIdStr) {
        return transportRecordService.updateIsSettleAccounts(isSettleAccounts,sendTimeKsrq,sendTimeJsrq,varietiesIdStr,supplierIdStr,receiverIdStr);
    }

}
